﻿using System;
using System.Web;
using WAD.WEB.AppCode;
using WAD.DAL;
using System.Collections.Generic;
using WAD.BLL;
namespace WAD.WEB.Client.Ajax
{
    /// <summary>
    /// Push 的摘要说明
    /// </summary>
    public class Push : AjaxBase
    {
        public override void AjaxMethodDispatch(String identity)
        {
            switch (identity)
            {
                case "setclient": this.SetClient(); break;
            }
        }
        /// <summary>
        /// 设置终端的系统类型，推送的Channelid (此方法设置后，终端才能收到推送)
        /// </summary>
        [QD.Web.Ajax.AjaxMethod]
        public void SetClient()
        {
            int user_id = Parse.Int("user_id", 0);
            int clientid = Parse.Int("clientid", 0);  // 1 安卓, 2苹果
            int store = Parse.Int("store", 0);
            string userid = Parse.String("userid", "");
            string channelid = Parse.String("channelid", "");
            if (clientid < 1)
                return;

            //不提示推送加载错误，直接返回 2016-12-21
            if (string.IsNullOrEmpty(channelid) || channelid.IndexOf("null") > -1)
                JsonResult(0, "");

            //if (string.IsNullOrEmpty(channelid) || channelid.IndexOf("null") > -1)
            //    JsonResult(11, "推送加载异常,请重新打开APP登录");

            if (DAOPush.AddOrUpdate(user_id, clientid, userid, channelid, store) > 0)
                Success();
            Fail();
        }
    }
}